package com.example.gametestproject;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.PointF;
import android.graphics.RectF;

import com.xxxx.game.ISprite;

public class UIControl {
	private boolean mIsPressDown;
	private Bitmap mSpriteNormal;
	private Bitmap mSpritePressdown;
	private PointF mPos;
	
	public UIControl()
	{
		this.mIsPressDown = false;
		this.mSpriteNormal = null;
		this.mSpritePressdown = null;
		this.mPos = new PointF(0,0);
	}
	
	public UIControl(Bitmap spriteNormal, Bitmap spritePD)
	{
		this.mIsPressDown = false;
		this.mSpriteNormal = spriteNormal;
		this.mSpritePressdown = spritePD;
		this.mPos = new PointF(0,0);
	}
	
	public UIControl(Bitmap spriteNormal, Bitmap spritePD, PointF ipos)
	{
		this.mIsPressDown = false;
		this.mSpriteNormal = spriteNormal;
		this.mSpritePressdown = spritePD;
		this.mPos = ipos;
		
	}
	
	public void setPressed(boolean isPressdown)
	{
		this.mIsPressDown = isPressdown;
	}
	public boolean isPressed()
	{
		return this.mIsPressDown;
	}
	
	public PointF getPosition()
	{
		return this.mPos;
	}
	
	public void setPosition(PointF ipos)
	{
		this.mPos = ipos;
	}
	
	public void paint(Canvas canvas)
	{
		if(this.mIsPressDown)
			canvas.drawBitmap(this.mSpritePressdown, this.mPos.x, this.mPos.y, new android.graphics.Paint());
		else
			canvas.drawBitmap(this.mSpriteNormal, this.mPos.x, this.mPos.y, new android.graphics.Paint());
	}
	
	public boolean containsPoint(float x, float y)
	{
		RectF rect = new RectF(this.mPos.x, this.mPos.y, this.mPos.x + this.mSpriteNormal.getWidth(), this.mPos.y + this.mSpriteNormal.getHeight() );
		
		return rect.contains(x, y);
	}
}
